package com.ocean.web.controller.product;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.historyProduct.domain.OHistoryProduct;
import com.ocean.historyProduct.service.IOHistoryProductService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 历史产品Controller
 *
 * @author ocean
 * @date 2023-02-13
 */
@Controller
@RequestMapping("/historyProduct/historyProduct")
public class OHistoryProductController extends BaseController
{
    private String prefix = "product/historyProduct";

    @Autowired
    private IOHistoryProductService oHistoryProductService;

    @RequiresPermissions("historyProduct:historyProduct:view")
    @GetMapping()
    public String historyProduct()
    {
        return prefix + "/historyProduct";
    }

    /**
     * 查询历史产品列表
     */
    @RequiresPermissions("historyProduct:historyProduct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OHistoryProduct oHistoryProduct)
    {
        startPage();
        List<OHistoryProduct> list = oHistoryProductService.selectOHistoryProductList(oHistoryProduct);
        return getDataTable(list);
    }

    /**
     * 导出历史产品列表
     */
    @RequiresPermissions("historyProduct:historyProduct:export")
    @Log(title = "历史产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OHistoryProduct oHistoryProduct)
    {
        List<OHistoryProduct> list = oHistoryProductService.selectOHistoryProductList(oHistoryProduct);
        ExcelUtil<OHistoryProduct> util = new ExcelUtil<OHistoryProduct>(OHistoryProduct.class);
        return util.exportExcel(list, "历史产品数据");
    }

    /**
     * 新增历史产品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史产品
     */
    @RequiresPermissions("historyProduct:historyProduct:add")
    @Log(title = "历史产品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OHistoryProduct oHistoryProduct)
    {
        return toAjax(oHistoryProductService.insertOHistoryProduct(oHistoryProduct));
    }

    /**
     * 修改历史产品
     */
    @RequiresPermissions("historyProduct:historyProduct:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OHistoryProduct oHistoryProduct = oHistoryProductService.selectOHistoryProductById(id);
        mmap.put("oHistoryProduct", oHistoryProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史产品
     */
    @RequiresPermissions("historyProduct:historyProduct:edit")
    @Log(title = "历史产品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OHistoryProduct oHistoryProduct)
    {
        return toAjax(oHistoryProductService.updateOHistoryProduct(oHistoryProduct));
    }

    /**
     * 删除历史产品
     */
    @RequiresPermissions("historyProduct:historyProduct:remove")
    @Log(title = "历史产品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oHistoryProductService.deleteOHistoryProductByIds(ids));
    }
}
